<template>
  <div class="chayan">
    <div class="wrapper">
      <div class="tab-items" ref="menuWrapper" :style="'height:' + setHeight">
        <ul>
          <li :class="{'active': indexs === index || item.id === indexs}" @click="showContent(index, $event)" class="items" v-for="(item,index) in checkList" :key="index">{{item.name}}</li>
        </ul>
      </div>
      <div class="items-container" ref="itemsWrapper" :style="'height:' + setHeight">
        <div>
          <ul v-if="indexs === key || item.id === indexs" v-for="(item,key) in checkList" :key="key">
            <li  class="container" v-for="(list, num) in item.data" :key="num">
              <div v-show="list.img.length" class="image" v-lazy:background-image="list.img[0]"></div>
              <img class="image" v-show="!list.img.length" src="../../../static/imgDefault.png" alt="">
              <div class="desc">
                <div class="all">
                  <p class="name">{{list.project_name}}</p>
                  <p class="lift-num" v-show="list.lift_num && list.lift_num != '0'">电梯编号：{{list.lift_num}}</p>
                  <!-- <p class="timer">{{list.created_at*1000 | datego(list.created_at*1000)}}</p> -->
                  <p class="timer">{{list.created_at*1000 | dateFmtt("yyyy-MM-dd")}}</p>
                  <!-- <p class="timer">{{list.created_at*1000 | date(list.created_at*1000)}}</p> -->
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import {getsortType} from '../../api/supervisor'
import BScroll from 'better-scroll'
export default {
  data () {
    return {
      checkList: [],
      indexs: 1,
      setHeight: '',
      scrollY: 0
    }
  },
  created () {
    this._getsortType()
    // this.$nextTick(() => {
    //   this._initScroll()
    //   this.menuScroll.refresh()
    //   this.itemsScroll.refresh()
    // })
  },
  mounted () {
    this.$nextTick(() => {
      this._initScroll()
      this.menuScroll.refresh()
      this.itemsScroll.refresh()
    })
    var screenHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
    this.setHeight = (screenHeight - 136) + 'px'
    console.log(this.setHeight)
  },
  methods: {
    _getsortType () {
      getsortType('month').then(res => {
        this.checkList = res.data.data
      })
    },
    showContent (index, e) {
      this.indexs = index
      // 点击菜单栏初始化better-scroll使每次点击的时候都保证内容在最顶部
      this.itemsScroll = new BScroll(this.$refs.itemsWrapper, {
        probeType: 3,
        click: true
      })
    },
    _initScroll () {
      this.menuScroll = new BScroll(this.$refs.menuWrapper, {
        click: true
      })
      this.itemsScroll = new BScroll(this.$refs.itemsWrapper, {
        probeType: 3,
        click: true
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .chayan{
    height: 100%;
    margin-top: 44px;
    .wrapper{
      display: flex;
      .tab-items{
        flex: 0 0 80px;
        width: 80px;
        background-color: #F2F2F2;
        .items{
          text-align: center;
          padding: 0 4px;
          height: 48px;
          line-height: 48px;
          border-bottom: 1px solid #fff;
          &:last-child{
            border-bottom: 1px solid transparent;
          }
        }
        .active {
          color: #0078de;
          font-size: 14px;
          background-color: #fff;
        }
      }
      .items-container{
        flex: 1;
        margin: 0 10px 0 6px;
        box-sizing: border-box; 
        .container{
          display: flex;
          padding: 7px 0;          
          border-bottom: 1px solid #f2f2f2;
          &:last-child{
            border-bottom: 1px solid transparent;
          }
          .image{
            flex: 0 0 60px;
            width: 60px;
            height: 60px;
            margin-right: 5px;
            background-size: cover;
          }
          .desc{
            flex: 1;
            display: flex;
            align-items: center;
            .all{
              flex: 1;
              .name{
                padding-bottom: 5px;
                font-size: 14px;
              }
              .lift-num{
                padding-bottom: 5px;
                color: #666;
              }
              .timer{
                color: #999;
              }
            }
          }
        }       
      }
    }
  }
</style>